import re

def use_greedy():
    s = "This is a number 234-235-22-423"
    ret = re.match(".+(\d+-\d+-\d+-\d+)", s)
    print(ret.group(1))
    print(re.match(r"aa(\d+)", "aa2343ddd").group(1))

    print(re.match(r"aa(\d+?)", "aa2343ddd").group(1))

    print(re.match(r"aa(\d+)ddd", "aa2343ddd").group(1))

    print(re.match(r"aa(\d+?)ddd", "aa2343ddd").group(1))

def use_r():
    """
    :r的作用，原生字串
    :return:
    """
    mm = r"c:\a\b\c"  # 使用原生字符串r，避免路径中的转义字符问题
    print(mm)

    # 正则表达式使用双反斜杠来匹配反斜杠
    result = re.match(r"c:\\", mm)

    if result:
        print(result.group())  # 使用 .group() 获取匹配的结果
    else:
        print("匹配失败")

def use_option():
    print(re.match(r'\w*', 'abc函', flags=re.A).group())  # re.A去汉字
    print(re.match(r'a*', 'aA', flags=re.I).group())    # re.I匹配不区分大小写
    print(re.match(r'.*', 'abc\ndef', flags=re.S).group())  # re.S可以让.匹配上\n

if __name__ == '__main__':
    # use_greedy()
    # use_r()
    use_option()